package com.gitee.wsl.flow.combine

import com.gitee.wsl.flow.F
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flattenMerge
import kotlinx.coroutines.flow.flowOf

fun <T> Flow<T>.merge(vararg flows: Flow<T>): Flow<T> = flowOf(*flows).flattenMerge()

/**
 * This function is an alias to [concatWith] operator.
 *
 * Returns a [Flow] that emits the items emitted from this [Flow], then the next, one after the other, without interleaving them.
 *
 * Example:
 * ``` kotlin
 * val flow1 = flowOf(1, 2, 3)
 * val flow2 = flowOf(4, 5, 6)
 * val result = flow1 + flow2 // produces the following emissions 1, 2, 3, 4, 5, 6
 * ```
 *
 * @see concatWith
 */
operator fun <T> Flow<T>.plus(other: Flow<T>): Flow<T> = F.concat(this, other)